#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>

int main()
{

    if (access("/home/gec/fifo1", F_OK) == -1)
    {
        int ret = mkfifo("/home/gec/fifo1", 0777);
        printf("ret = %d\n", ret); // 0 成功 -1 失败
    }
    else
    {
        printf("fifo1 is exist\n");
    }

    int fd = open("/home/gec/fifo1", O_RDWR);

    while (1)
    {
        char buf[32] = {0};
        read(fd, buf, sizeof(buf));
        printf("buf = %s\n", buf);
    }

    close(fd);
    return 0;
}